#ifndef     __CONFIG_H
#define     __CONFIG_H

#include "../utils/store.h"

namespace service {

using namespace driver;

struct Config {

    int32_t FetchAdj;
    uint32_t PushAdj;
    uint32_t OtaPkgSize;
    uint32_t AppAddr;
    uint32_t OtaAddr;

    void OtaInit(uint32_t pkgsize) {
        OtaPkgSize = pkgsize;
        AppAddr = flash::AppAddr;
        OtaAddr = flash::OtaAddr;
    }

    void OtaReset() {
        OtaPkgSize = 0;
        AppAddr = 0;
        OtaAddr = 0;
    }

    bool Verify() const {
        return  (OtaPkgSize > 0) &&
                (OtaPkgSize < flash::AppSize) &&
                (AppAddr == flash::AppAddr) &&
                (OtaAddr == flash::OtaAddr);
    }

    void reset() {
        FetchAdj = 0;
        PushAdj = 635;
        OtaPkgSize = 0;
        AppAddr = 0;
        OtaAddr = 0;
    }
};

extern utils::Store<Config, flash::DataAddr> config;

}


#endif
